package com.formulas.certification;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import org.apache.ibatis.annotations.Mapper;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author yiwannuofulasi
 * @date 2023/5/30 17:21
 */
public class CertificationGeneratorConfig {

    public static void main(String[] args) {
        List<String> tables = new ArrayList<>();
        tables.add("oauth_client_details");
        FastAutoGenerator.create("jdbc:mysql://127.0.0.1:3306/formulas-certification?characterEncoding=UTF-8&useSSL=true&rewriteBatchedStatements=true&serverTimezone=Asia/Shanghai","root","root")
                .globalConfig(builder -> builder.author("坚持是一种技术")
                        .outputDir(System.getProperty("user.dir")+"\\formulas-certification\\certification-infrastructure\\src\\main\\java")
                        .enableSwagger()
                        .commentDate("yyyy-MM-dd"))
                .packageConfig(builder -> builder.parent("com.formulas.certification")
                        .moduleName("oauth")
                        .entity("entity")
                        .mapper("mapper")
                        .xml("mapper")
                        .pathInfo(Collections.singletonMap(OutputFile.xml,
                                System.getProperty("user.dir")+"\\formulas-certification\\certification-infrastructure\\src\\main\\java\\com\\formulas\\certification\\oauth\\mapper")))
                .strategyConfig(builder -> {
                    builder.addInclude(tables)
                            .serviceBuilder()
                            .formatServiceFileName("%sService")
                            .formatServiceImplFileName("%sServiceImpl")
                            .entityBuilder()
                            .enableFileOverride()
                            .enableLombok()
                            .logicDeleteColumnName("deleted")
                            .enableTableFieldAnnotation()
                            .controllerBuilder()
                            .enableHyphenStyle()
                            .formatFileName("%sController")
                            .enableRestStyle()
                            .mapperBuilder()
                            .enableBaseResultMap()
                            .superClass(BaseMapper.class)
                            .formatMapperFileName("%sMapper")
                            .formatXmlFileName("%sMapper")
                            .mapperAnnotation(Mapper.class)
                            .enableFileOverride();
                })
                .templateConfig(builder -> {
                    builder.entity("templates/CustomizedEntity.java");
                })
                .templateEngine(new FreemarkerTemplateEngine())
                .templateConfig(builder -> builder.controller(""))
                .execute();
    }
}
